package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.cpu.PicInstructionFacade;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.util.Bits;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 2:12:57 PM
 */
public abstract class BitSupport implements PicInstruction {
    private final Bits fileArg;
    private final int bitArg;

    protected BitSupport(final Bits fileArg, final int bitArg) {
        this.fileArg = fileArg;
        this.bitArg = bitArg;
    }

    @NotNull
    @Override
    public final List<? extends PicAction> getActions(@NotNull final PicInstructionFacade pic) {
        return new InstructionSupport(false, false, fileArg) {
            @NotNull
            @Override
            protected RegisterValue getValue(@NotNull final RegisterValue addressedFile,
                                             @NotNull final RegisterValue wRegister,
                                             @NotNull final List<PicAction> yourActions,
                                             @NotNull final ActionFactory actionFactory) {
                return doBitCommand(addressedFile, bitArg, yourActions, actionFactory);
            }
        }.getActions(pic);
    }

    protected abstract RegisterValue doBitCommand(RegisterValue addressedFile, int bitArg, List<PicAction> yourActions,
                                                  ActionFactory actionFactory);
}

